package myauctioneer.service;

import myauctioneer.dao.RatingDAO;
import myauctioneer.dao.RatingDAOI;
import myauctioneer.dao.RatingDetailDAO;
import myauctioneer.dao.RatingDetailDAOI;
import myauctioneer.dto.Article;
import myauctioneer.dto.Rating;
import myauctioneer.dto.RatingDetail;

public class SalesService {

	private RatingDetailDAOI rddao;
	private RatingDAOI rdao;

	public SalesService() {
		try {
			this.rddao = new RatingDetailDAO();
			this.rdao = new RatingDAO();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public boolean placeRatingDetail(String labeling, String note, String time) {
		if ((labeling == null || labeling.trim() == "")
				|| (note == null || note.trim() == "")
				|| (time == null || time.trim() == "")) {
			return false;
		} else {
			RatingDetail ratingDetail = new RatingDetail(labeling, note, time);
			rddao.saveRatingDetail(ratingDetail);
			return true;
		}
	}

	public boolean placeRating(int userId, int articleId, int ratingDetailId,
			String type) {
		Rating rating = new Rating(userId, articleId, ratingDetailId, type);
		rdao.saveRating(rating);
		return true;
	}

	public RatingDetail loadRatingDetailByLabelingNote(String labeling,
			String note) {
		return rddao.loadRatingDetailByLabelingNote(labeling, note);
	}
}
